package com.qj.yantaishan.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import com.qj.yantaishan.mapper.CommentMapper;
import com.qj.yantaishan.domain.Comment;
import com.qj.yantaishan.service.ICommentService;
import com.qj.yantaishan.common.core.text.Convert;

/**
 * 评论Service业务层处理
 *
 * @author qihe
 * @date 2022-07-22
 */
@Service
@Primary
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;

    /**
     * 查询评论
     *
     * @param id 评论主键
     * @return 评论
     */
    @Override
    public Comment selectCommentById(Long id) {
        return commentMapper.selectCommentById(id);
    }

    /**
     * 查询评论列表
     *
     * @param comment 评论
     * @return 评论
     */
    @Override
    public List<Comment> selectCommentList(Comment comment) {
        return commentMapper.selectCommentList(comment);
    }

    /**
     * 新增评论
     *
     * @param comment 评论
     * @return 结果
     */
    @Override
    public int insertComment(Comment comment) {
        return commentMapper.insertComment(comment);
    }

    /**
     * 修改评论
     *
     * @param comment 评论
     * @return 结果
     */
    @Override
    public int updateComment(Comment comment) {
        return commentMapper.updateComment(comment);
    }

    /**
     * 批量删除评论
     *
     * @param ids 需要删除的评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentByIds(String ids) {
        return commentMapper.deleteCommentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除评论信息
     *
     * @param id 评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentById(Long id) {
        return commentMapper.deleteCommentById(id);
    }

    @Override
    public Map<String, Object> mySelectCommentList(Integer currentPage, Integer pageSize) {
        Map<String, Object> result = new HashMap<>();
        int total = commentMapper.total();
        List<Comment> comments=commentMapper.mySelectCommentList();
        int current = (currentPage - 1) * pageSize;
        int pages = ((total + pageSize) - 1) / pageSize;
        result.put("total" , total);
        result.put("current" , currentPage);
        result.put("pages" , pages);
        result.put("pageSize" , pageSize);
        result.put("records",comments);
        return result;
    }
}
